<template>
  <NavBar />
  <div class="homePage">
    <Scroll @scroll="scrollList"  class="list">
      <div class="scroll-content">
        <div class="banners">
          <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
            <van-swipe-item v-for="(item, index) in swipeList" :key="index">
              <img :src="item.img_url" :alt="item.title">
            </van-swipe-item>
          </van-swipe>
        </div>
        <recommend :recommendList="recommendList" />
        <TabControl @tabClick="tabClicks" :title="['畅销', '新书', '精选']" />
        <div>1</div>
        <div>1</div>
        <div>1</div>
        <div>1</div>
        <div>1</div>
        <div>1</div>
        <div>1</div>
        <div>1</div>
        <div>1</div>
        <div>1</div>
        <div>1</div>
        <div>1</div>
        <div>1</div>
        <div>1</div>
        <div>1</div>
        <div>1</div>
        <div>1</div>
        <div>1</div>
        <div>1</div>
        <div>1</div>
        <div>1</div>
        <div>1</div>
        <div>1</div>
        <div>1</div>
        <div>1</div>
        <div>1</div>
        <div>1</div>
        <div>1</div>
        <div>1</div>
        <div>1</div>
        <div>1</div>
        <div>1</div>
        <div>1</div>
        <div>1</div>
        <div>1</div>
        <div>1</div>
        <div>1</div>
        <div>1</div>
        <div>1</div>
        <div>1</div>
        <div>1</div>
        <div>1</div>
        <div>9</div>
      </div>
    </Scroll>
  </div>
</template>

<script>
import recommend from './components/Recommend.vue'
import {getHomeAllData} from 'network/home.js'
import { ref } from '@vue/reactivity'
import { onMounted } from '@vue/runtime-core'
import Scroll from '../../components/common/scroll/scroll.vue'
export default {
  components: {
    recommend,
    Scroll
  },
  setup() {
    let swipeList = ref([])
    let recommendList = ref([])
    function scrollList(pos) {
      console.log(pos)
    }
    onMounted(() => {
      getHomeAllData().then(response => {
        swipeList.value = response.slides
        recommendList.value = response.goods.data
      })
    })
    function tabClicks(index) {
      console.log(index)
    }
    return {
      scrollList,
      swipeList,
      recommendList,
      tabClicks
    } 
  }
}
</script>

<style lang="scss" scoped>
.homePage {
  overflow: hidden;
  position: fixed;
  top: 45px;
  bottom: 50px;
  width: 100vw;
  // overflow-y: auto;
  .list {
    height: 100%;
  }
  .banners {
    width: 100%;
    height: 200px;
    img {
      width: 100%;
      height: 200px;
    }
  }
}
</style>